<?php
require '../../../../_core/common.php';

//权限验证
if( Role::init() == false ){
	exit('没有权限');
}

$orders = isset($_POST['orders']) ? $_POST['orders'] : array();
$title_id = isset($_POST['title_id']) ? $_POST['title_id'] : array();

if( empty($orders) || empty($title_id) || count($orders)!=count($title_id) ){
	echo '<script>alert("参数有误!");window.history.go(-1);</script>';
	exit;
}

$db = new DB('star');

$orders_title_id_array = array();
foreach($title_id as $k=>$v){
	$orders_title_id_array[$v] = $orders[$k];
}

foreach($orders_title_id_array as $key=>$val){
	$title_id = intval($key);
	$orders = intval($val);
	if( $title_id > 0 ){
		$data = array('orders'=>$orders);
		$db->table('star')->where('title_id='.$title_id)->update($data)->run();
	}
}

echo '<script>alert("成功更新排序！");window.location.href="/www/admin/star/star_lists.php";</script>';
exit;